package com.sxm.yiwei.tools;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.sxm.yiwei.R;


/**
 * Created by KuKa on 2017/8/29.
 */

public class PayWindow extends PopupWindow {

    private final View view;
    public final Button paybt;
    public String psd;
    PayBtOnclick payBtOnclick;
    public TextView paywinPrice;
    private final TextView forgetpsd;

    public PayWindow(final Context context) {
        view = LayoutInflater.from(context).inflate(R.layout.paywindow, null);
        final PayPsdInputView pass = (PayPsdInputView) view.findViewById(R.id.password);
        paybt = (Button) view.findViewById(R.id.sure_pay);
        forgetpsd = (TextView) view.findViewById(R.id.pay_forgetpsd);
        paywinPrice = (TextView) view.findViewById(R.id.paywindow_money);
        forgetpsd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (payBtOnclick!=null){
                    payBtOnclick.payForgetClick();
                }
            }
        });
        paybt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                psd = pass.getText().toString();
                if (payBtOnclick!=null){
                    payBtOnclick.payOnClick(psd);
                }
            }
        });
           /* 设置弹出窗口特征 */
        // 设置视图
        this.setContentView(this.view);
        // 设置弹出窗体的宽和高
        this.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);
        this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
        // 设置弹出窗体可点击
        this.setFocusable(true);
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        // 设置弹出窗体的背景
        this.setBackgroundDrawable(dw);

    }
    public interface PayBtOnclick{
       void payOnClick(String word);
        void payForgetClick();
    }
    public void setPayBtOnclick(PayBtOnclick payBtOnclick){
        this.payBtOnclick=payBtOnclick;
    }
}
